package com.ruoyi.project.cms.content.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.content.domain.Content;
import com.ruoyi.project.cms.content.service.IContentService;
import com.ruoyi.project.system.config.service.IConfigService;
import com.ruoyi.project.system.notice.domain.Notice;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.soap.Addressing;
import java.util.List;

@Controller
@RequestMapping("/cms/content")
public class ContentManagerController  extends BaseController {
    //生命业务层属性
    @Autowired
    private IContentService contentService;

    private String prifex="cms/content";
    //静态页面跳转 请求转发
    @GetMapping
    @RequiresPermissions("cms:content:view")
    public String view(){

        return prifex+"/contentview";

    }

    /**
     * 查询公告列表
     */
    @RequiresPermissions("cms:content:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Content content)
    {
        startPage();
        List<Notice> list = contentService.selectContentList(content);
        return getDataTable(list);
    }



    /**
     * 新增公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prifex + "/add";
    }

    /**
     * 新增保存公告
     */
    @RequiresPermissions("cms:content:add")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Content  content)
    {
        return toAjax(contentService.insertContent(content));
    }


    /**
     * 删除公告
     */
    @RequiresPermissions("cms:content:remove")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contentService.deleteContentByIds(ids));
    }


    /**
     * 修改公告
     */
    @GetMapping("/edit/{contentId}")
    public String edit(@PathVariable("contentId") Long contentId, ModelMap mmap)
    {
        mmap.put("content", contentService.selectContentById(contentId));
        return prifex + "/edit";
    }

    /**
     * 修改保存公告
     */
    @RequiresPermissions("cms:content:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Content content)
    {
        return toAjax(contentService.updateContent(content));
    }


    /**
     * 修改公告
     */
    @GetMapping("/look")
    public String look( Long contentId, ModelMap mmap)
    {
        System.out.println(contentId);
        mmap.put("content", contentService.selectContentById(contentId));
        return prifex + "/look";
    }

    @RequiresPermissions("cms:content:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/look")
    @ResponseBody
    public AjaxResult look(Content content)
    {
        return toAjax(contentService.updateContent(content));
    }

}
